Scalar Functions

You can use scalar functions in SQL statements with the following syntax:

{fn scalar-function} 

where scalar-function is a scalar function supported by the ODBC driver, JDBC driver, and .NET data provider, as shown in the following tables.

scalar-function

Example:

SELECT {fn UCASE(NAME)} FROM EMP 
 

Table A-2. Scalar Functions Supported on DB2 

Data Store
String
Functions
Numeric Functions
Timedate Functions
System Functions
DB2 UDB on z/OS
CHAR
CONCAT
DIFFERENCE
INSERT
LCASE
LEFT
LENGTH
LOCATE
LOCATE_2
LTRIM
REPEAT
REPLACE
RIGHT
RTRIM
SOUNDEX
SPACE
SUBSTRING
UCASE
ABS
ACOS
ASIN
ATAN
ATAN2
CEILING
COS
DEGREES
EXP
FLOOR
LOG
LOG10
MOD
PI
POWER
RADIANS
RAND
ROUND
SIGN
SIN
SQRT
TAN
TRUNCATE
CURDATE
CURRENT_DATE
CURTIME
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
HOUR
MINUTE
MONTH
NOW
SECOND
WEEK
YEAR
DBNAME
IFNULL
USERNAME
DB2 UDB on Linux/UNIX/ Windows
ASCII
CHAR
CONCAT
DIFFERENCE
INSERT
LCASE
LEFT
LENGTH
LOCATE
LOCATE_2
LTRIM
REPEAT
REPLACE
RIGHT
RTRIM
SOUNDEX
SPACE
SUBSTRING
UCASE
ABS
ACOS
ASIN
ATAN
ATAN2
CEILING
COS
COT
DEGREES
EXP
FLOOR
LOG
LOG10
MOD
PI
POWER
RADIANS
RAND
ROUND
SIGN
SIN
SQRT
TAN
TRUNCATE
CURDATE
CURRENT_DATE
CURTIME
DAYNAME
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
HOUR
MINUTE
MONTH
MONTHNAME
NOW
QUARTER
SECOND
TIMESTAMPADD
TIMESTAMPDIFF
WEEK
YEAR
DATABASE
IFNULL
USERNAME

Table A-3. Scalar Functions Supported on Informix 

Data Store
String
Functions
Numeric Functions
Timedate Functions
System Functions
Informix
BIT_LENGTH
CHAR_LENGTH
CONCAT
LENGTH
LTRIM
RTRIM
STR_LENGTH
ABS
ACOS
ASIN
ATAN
ATAN2
COS
COT
EXP
FLOOR
LOG
LOG10
MOD
POWER
ROUND
SQRT
TAN
TRUNCATE
CURDATE
CURRENT DATE
CURTIME
DAYOFMONTH
DAYOFWEEK
MONTH
NOW
QUARTER
YEAR
DBNAME
USERNAME

Table A-4. Scalar Functions Supported on Microsoft SQL Server 

Data Store
String
Functions
Numeric Functions
Timedate Functions
System Functions
Microsoft
SQL Server
ASCII
BITLENGTH
CHAR
CONCAT
DIFFERENCE
INSERT
LCASE
LEFT
LENGTH
LOCATE
LOCATE2
LTRIM
OCTET_LENGTH
REPEAT
REPLACE
RIGHT
RTRIM
SOUNDEX
SPACE
SUBSTRING
UCASE
ABS
ACOS
ASIN
ATAN
ATAN2
CEILING
COS
COT
DEGREES
EXP
FLOOR
LOG
LOG10
MOD
PI
POWER
RADIANS
RAND
ROUND
SIGN
SIN
SQRT
TAN
TRUNCATE
CURDATE
CURRENT_DATE
CURRENT_TIME
CURRENT_ TIMESTAMP
CURTIME
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
DAYNAME
EXTRACT
HOUR
MINUTE
MONTH
MONTHNAME
NOW
QUARTER
SECOND
TIMESTAMPADD
TIMESTAMPDIFF
WEEK
YEAR
DBNAME
IFNULL
USERNAME

Table A-5. Scalar Functions Supported on Oracle 

Data Store
String
Functions
Numeric Functions
Timedate Functions
System Functions
Oracle
ASCII
BIT_LENGTH
CHAR
CONCAT
INSERT
LCASE
LEFT
LENGTH
LOCATE
LOCATE2
LTRIM
OCTET_LENGTH
REPEAT
REPLACE
RIGHT
RTRIM
SOUNDEX
SPACE
SUBSTRING
UCASE
ABS
ACOS
ASIN
ATAN
ATAN2
CEILING
COS
COT
EXP
FLOOR
LOG
LOG10
MOD
PI
POWER
ROUND
SIGN
SIN
SQRT
TAN
TRUNCATE
CURDATE
CURRENT_DATE
CURRENT_TIME
CURRENT TIMESTAMP
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
DAYNAME
HOUR
MINUTE
MONTH
MONTHNAME
NOW
QUARTER
SECOND
TIMESTAMP_ADD
TIMESTAMP_DIFF
WEEK
YEAR
IFNULL
USER
USERNAME

Table A-6. Scalar Functions Supported on Sybase

Data Store
String
Functions
Numeric Functions
Timedate Functions
System Functions
Sybase
ASCII
CHAR
CONCAT
DIFFERENCE
INSERT
LCASE
LEFT
LENGTH
LOCATE
LTRIM
REPEAT
RIGHT
RTRIM
SOUNDEX
SPACE
SUBSTRING
UCASE
ABS
ACOS
ASIN
ATAN
ATAN2
CEILING
COS
COT
EXP
FLOOR
LOG
LOG10
MOD
NUM_DEGREES
NUM_RADIANS
PI
POWER
RADIANS
RAND
ROUND
SIGN
SIN
SQRT
TAN
TRUNCATE
CURDATE
CURRENT_DATE
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
DAYNAME
HOUR
MINUTE
MONTH
MONTHNAME
NOW
QUARTER
SECOND
TIMESTAMPADD
TIMESTAMPDIFF
WEEK
YEAR
DATABASE
DBNAME
IFNULL
USER
USERNAME

String Functions

Table A-7 lists string functions. The following arguments can be used with these functions:

The string functions are one-based; that is, the first character in the string is the character 1. Character string literals must be enclosed by single quotation marks.

Table A-7. Scalar String Functions 
Function
Returns
ASCII(string_exp)
The ASCII code of the leftmost character of string_exp as an integer.
BIT_LENGTH(string_exp)
The length, in bits, of the string expression.
CHAR(code)
The character with the ASCII code specified by code. code should be between 0 and 255; otherwise, the return value depends on the data source.
CHAR_LENGTH(string_exp)
The length, in characters, of the string expression, when the string expression is a character data type; otherwise, the length, in bytes, of the string expression (the lowest integer that is not less than the number of bits divided by 8). (This function is the same as the CHARACTER_LENGTH function.)
CHARACTER_LENGTH(string_exp)
The length, in characters, of the string expression, when the string expression is a character data type; otherwise, the length, in bytes, of the string expression (the lowest integer that is not less than the number of bits divided by 8). (This function is the same as the CHAR_LENGTH function.)
CONCAT(string_exp1, string_exp2)
The string resulting from concatenating string_exp2 and string_exp1. The string is system dependent.
DIFFERENCE(string_exp1, string_exp2)
An integer indicating the difference between the values returned by the SOUNDEX function for string_exp1 and string_exp2.
INSERT(string_exp1, start, length, string_exp2)
A string where length characters have been deleted from string_exp1 beginning at start and where string_exp2 has been inserted into string_exp beginning at start.
LCASE(string_exp)
Uppercase characters in string_exp converted to lowercase.
LEFT(string_exp,count)
The count of characters of string_exp.
LENGTH(string_exp)
The number of characters in string_exp, excluding trailing blanks and the string termination character.
LOCATE(string_exp1, string_exp2[,start])
The starting position of the first occurrence of string_exp1 in string_exp2. If start is not specified, the search begins with the first character position in string_exp2. If start is specified, the search begins with the character position indicated by start. The first character position in string_exp2 is indicated by 1. If string_exp1 is not found, 0 is returned.
LTRIM(string_exp)
The characters of string_exp, with leading blanks removed.
OCTET_LENGTH(string_exp)
The length, in bytes, of the string expression. The result is the lowest integer that is not less than the number of bits divided by 8.
POSITION(character_exp IN character_exp)
The position of the first character expression in the second character expression. The result is a numeric with an implementation-defined precision and a scale of 0.
REPEAT(string_exp, count)
A string composed of string_exp repeated count times.
REPLACE(string_exp1, string_exp2, string_exp3)
Replaces all occurrences of string_exp2 in string_exp1 with string_exp3.
RIGHT(string_exp, count)
The rightmost count of characters in string_exp.
RTRIM(string_exp)
The characters of string_exp with trailing blanks removed.
SOUNDEX(string_exp)
A data-source dependent string representing the sound of the words in string_exp.
SPACE(count)
A string consisting of count spaces.
SUBSTRING(string_exp, start, length)
A string derived from string_exp, beginning at the character position start for length characters.
UCASE(string_exp)
Lowercase characters in string_exp converted to uppercase.

Numeric Functions

Table A-8 lists numeric functions. The following arguments can be used with numeric functions:

Date and Time Functions

Table A-9 lists date and time functions. The following arguments can be used with the date and time functions:

System Functions

Table A-10 lists system functions.

Table A-10. Scalar System Functions
Function
Returns
DATABASE()
Name of the database, corresponding to the connection handle (hdbc).
IFNULL(exp,value)
value, if exp is null.
USER()
Authorization name of the user.